@model PagedResult<WorkFlowCore.BusinessDemo.Web.Models.WorkTaskStateInfoViewModel>

@{
    ViewData["Title"] = "工作任务状态列表";
}

<h2>工作任务状态列表</h2>

@if (TempData["SuccessMessage"] != null)
{
    <div class="alert alert-success" role="alert">@TempData["SuccessMessage"]</div>
}
@if (TempData["InfoMessage"] != null)
{
    <div class="alert alert-info" role="alert">@TempData["InfoMessage"]</div>
}
@if (TempData["ErrorMessage"] != null)
{
    <div class="alert alert-danger" role="alert">@TempData["ErrorMessage"]</div>
}

<div class="row mb-3">
    <div class="col-md-12">
        <form method="get" class="form-inline">
           
            <button type="submit" class="btn btn-primary">查询</button>
            <a asp-action="SyncAllStates" asp-controller="WorkTaskStateInfo" class="btn btn-info ml-2">同步状态</a>
        </form>
    </div>
</div>

<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th>实体全称</th>
                <th>实体主键值</th>
                <th>状态</th>
                <th>流程名称</th>
                <th>更新时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Items)
            {
                <tr>
                    <td>@item.EntityFullName</td>
                    <td>@item.EntityKeyValue</td>
                    <td>@item.StatusDisplay</td>
                    <td>@item.ProcessName</td>
                    <td>@item.UpdatedTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                    <td>
                        <a asp-action="Details" asp-route-id="@item.Id" class="btn btn-sm btn-info">详情</a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>

@{
    var prevDisabled = Model.PageIndex <= 1 ? "disabled" : "";
    var nextDisabled = Model.PageIndex >= Math.Ceiling((double)Model.TotalCount / Model.PageSize) ? "disabled" : "";
    var totalPages = Math.Max(1, (int)Math.Ceiling((double)Model.TotalCount / Model.PageSize));
}

<nav aria-label="Page navigation">
    <ul class="pagination justify-content-center">
        <li class="page-item @prevDisabled">
            <a class="page-link" asp-action="Index" asp-route-page="1" asp-route-pageSize="@Model.PageSize">首页</a>
        </li>
        <li class="page-item @prevDisabled">
            <a class="page-link" asp-action="Index" asp-route-page="@(Model.PageIndex - 1)" asp-route-pageSize="@Model.PageSize">上一页</a>
        </li>
        
        @for (int i = Math.Max(1, Model.PageIndex - 2); i <= Math.Min(totalPages, Model.PageIndex + 2); i++)
        {
            <li class="page-item @(i == Model.PageIndex ? "active" : "")">
                <a class="page-link" asp-action="Index" asp-route-page="@i" asp-route-pageSize="@Model.PageSize">@i</a>
            </li>
        }
        
        <li class="page-item @nextDisabled">
            <a class="page-link" asp-action="Index" asp-route-page="@(Model.PageIndex + 1)" asp-route-pageSize="@Model.PageSize">下一页</a>
        </li>
        <li class="page-item @nextDisabled">
            <a class="page-link" asp-action="Index" asp-route-page="@totalPages" asp-route-pageSize="@Model.PageSize">末页</a>
        </li>
    </ul>
</nav>

<div class="text-muted text-center">
    显示 @(((Model.PageIndex - 1) * Model.PageSize) + 1) 到 @(Math.Min(Model.PageIndex * Model.PageSize, Model.TotalCount)) 条，共 @Model.TotalCount 条记录
</div>
